package jdbc.test;

import cn.myschool.java79.util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author oldliu
 * @since 1.0
 */
public class SelectOrderby {
    public static void main(String[] args) {
        String sql = "select stuno,sname,qq,enterdate from s_student order by ? desc";
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            con = DBUtil.getConnection();
            ps = con.prepareStatement(sql);
            ps.setString(1, "stuno");

            rs = ps.executeQuery();
            while (rs.next()) {
                System.out.print(rs.getLong("stuno") + " ");
                System.out.print(rs.getString("sname") + " ");
                System.out.print(rs.getString("qq") + " ");
                System.out.println(rs.getDate("enterdate") );
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
        }
    }
}
